﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PhatPhucLoc.util;
using System.Data;
using PhatPhucLoc.model;
using System.Data.SqlClient;

namespace PhatPhucLoc.dao
{
    class HangHoaDAO
    {
        public static DataTable GetAll()
        {
            return DataUtil.executeStore("sp_HangHoa_GetAll", null);
        }

        public static Boolean Insert(HangHoaModel _model)
        {
            SqlParameter[] param = new SqlParameter[5];
            int i = 0;
            param[i] = new SqlParameter("ten", SqlDbType.NVarChar);
            param[i++].Value = _model.Ten;
            param[i] = new SqlParameter("ma_hang", SqlDbType.NVarChar);
            param[i++].Value = _model.MaHang;
            param[i] = new SqlParameter("ma_nhom_hang", SqlDbType.NVarChar);
            param[i++].Value = _model.MaNhomHang;
            param[i] = new SqlParameter("ghi_chu", SqlDbType.NVarChar);
            param[i++].Value = _model.GhiChu;
            param[i] = new SqlParameter("gia_nhap", SqlDbType.NVarChar);
            param[i++].Value = _model.GiaNhap;
            return DataUtil.executeNonStore("sp_HangHoa_Insert", param);
        }

        public static Boolean Update(HangHoaModel _model)
        {
            SqlParameter[] param = new SqlParameter[6];
            int i = 0;
            param[i] = new SqlParameter("id", SqlDbType.NVarChar);
            param[i++].Value = _model.Id;
            param[i] = new SqlParameter("ten", SqlDbType.NVarChar);
            param[i++].Value = _model.Ten;
            param[i] = new SqlParameter("ma_hang", SqlDbType.NVarChar);
            param[i++].Value = _model.MaHang;
            param[i] = new SqlParameter("ma_nhom_hang", SqlDbType.NVarChar);
            param[i++].Value = _model.MaNhomHang;
            param[i] = new SqlParameter("ghi_chu", SqlDbType.NVarChar);
            param[i++].Value = _model.GhiChu;
            param[i] = new SqlParameter("gia_nhap", SqlDbType.NVarChar);
            param[i++].Value = _model.GiaNhap;
            return DataUtil.executeNonStore("sp_HangHoa_Update", param);
        }

    }
}
